package org.example;

import org.springframework.aop.AfterReturningAdvice;
import org.springframework.aop.MethodBeforeAdvice;
import org.springframework.aop.ThrowsAdvice;

import java.lang.reflect.Method;

/**
 * ClassName: WuDaMethodBeforeAdvice
 * Package: org.example
 * Description: 早期用法
 *
 * @Author wanghao
 * @Create 2024-07-09 8:29
 * @Version 1.0
 */
public class WuDaMethodBeforeAdvice implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {  // 代码侵入  代码污染
    @Override
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        if (method.getName().endsWith("Bing")) {
            song();
        }
    }

    private void song() {
        System.out.println("送大麦茶...");
    }

    @Override
    public void afterReturning(Object o, Method method, Object[] objects, Object o1) throws Throwable {

    }
}
